package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.DictionarySingle;
import cn.wolfcode.crm.service.IDictionarySingleService;
import cn.wolfcode.crm.util.JsonResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("dictionarySingle")
public class DictionarySingleController {
    @Autowired
    private IDictionarySingleService dictionarySingleService;

    @RequiresPermissions("dictionarySingle:index")
    @RequestMapping("")
    public String index(){
        return "dictionary/list";
    }

    @RequiresPermissions("dictionarySingle:list")
    @RequestMapping("list")
    @ResponseBody
    public List<DictionarySingle> list(){
        return dictionarySingleService.getAll();

    }

    @RequestMapping("save")
    @ResponseBody
    @RequiresPermissions("dictionarySingle:save")
    public JsonResult save(DictionarySingle entity){
        JsonResult result = new JsonResult();
        try {
            dictionarySingleService.save(entity);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("保存操作失败");
        }
        return result;
    }

    @RequestMapping("update")
    @ResponseBody
    @RequiresPermissions("dictionarySingle:update")
    public JsonResult update(DictionarySingle entity){
        JsonResult result = new JsonResult();
        try {
            dictionarySingleService.update(entity);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("编辑操作失败");
        }
        return result;
    }

    @RequestMapping("delete")
    @ResponseBody
    @RequiresPermissions("dictionarySingle:delete")
    public JsonResult delete(Long id){
        JsonResult result = new JsonResult();
        try {
            dictionarySingleService.delete(id);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("删除操作失败");
        }
        return result;
    }

}
